<template>
<div>
    <el-form :model="inputForm" ref="inputForm" v-loading="loading"   :disabled="formReadOnly"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="24">
            <el-form-item label="设备名称" prop="basicdataEquipmentName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicdataEquipmentName" placeholder="请填写设备名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="部件名称" prop="basicdataPart"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicdataPart" placeholder="请填写部件名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="给油脂部位" prop="basicdataUnit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicdataUnit" placeholder="请填写给油脂部位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="润滑方式" prop="basicdataOiling"
                :rules="[
                 ]">
                <el-select v-model="inputForm.basicdataOiling" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('basticdata_giveoile_standard_lubrication')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="油脂牌号" prop="basicdataMark"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicdataMark" placeholder="请填写油脂牌号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="润滑点数" prop="basicdataIndex"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicdataIndex" placeholder="请填写润滑点数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="分工" prop="basicdataCheck"
                :rules="[
                 ]">
                    <el-radio-group v-model="inputForm.basicdataCheck">
                        <el-radio v-for="item in $dictUtils.getDictList('check_job')" :label="item.value" :key="item.id">{{item.label}}</el-radio>
                    </el-radio-group>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="给油脂油量" prop="basicdataOil"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicdataOil" placeholder="请填写给油脂油量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="给油脂周期" prop="basicdataPeriod"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicdataPeriod" placeholder="请填写给油脂周期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="给油脂责任人" prop="tuser.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.tuser.id" @getValue='(value) => {inputForm.tuser.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="更换油脂油量" prop="basicdataOilMeasure"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicdataOilMeasure" placeholder="请填写更换油脂油量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="更换油脂周期" prop="basicdataCircle"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicdataCircle" placeholder="请填写更换油脂周期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="更换油脂责任人" prop="tuse.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.tuse.id" @getValue='(value) => {inputForm.tuse.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
</div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        loading: false,
        inputForm: {
          id: '',
          basicdataEquipmentName: '',
          basicdataPart: '',
          basicdataUnit: '',
          basicdataOiling: '',
          basicdataMark: '',
          basicdataIndex: '',
          basicdataCheck: '',
          basicdataOil: '',
          basicdataPeriod: '',
          tuser: {
            id: ''
          },
          basicdataOilMeasure: '',
          basicdataCircle: '',
          tuse: {
            id: ''
          },
          remarks: ''
        }
      }
    },
    props: {
      businessId: {
        type: String,
        default: ''
      },
      formReadOnly: {
        type: Boolean,
        default: false
      }
    },
    components: {
      UserSelect
    },
    watch: {
      'businessId': {
        handler (newVal) {
          if (this.businessId) {
            this.init(this.businessId)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        },
        immediate: true,
        deep: false
      }
    },
    methods: {
      init (id) {
        if (id) {
          this.loading = true
          this.inputForm.id = id
          this.$nextTick(() => {
            this.$refs.inputForm.resetFields()
            this.$http({
              url: `/check/checkgiveoil/checkGiveOil/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.checkGiveOil)
              this.loading = false
            })
          })
        }
      },
      // 表单提交
      saveForm (callback) {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/check/checkgiveoil/checkGiveOil/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                callback(data.businessTable, data.businessId)
              }
            })
          }
        })
      }
    }
  }
</script>